// ==UserScript==
// @name         测试
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.nowcoder.com/*
// @match        https://blog.csdn.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nowcoder.com
// @grant        none
// @require      https://code.jquery.com/jquery-1.11.3.min.js
// ==/UserScript==
(function() {
    'use strict';
    let mark=12;
    var clock ='';
    clock = setInterval(countDown, 300); //一秒执行一次
    function countDown(){
        mark--;
       if(mark > 0){
           var keyJson = localStorage.getItem('monkeyVoidAd');
           keyJson = JSON.parse(keyJson);
           for(var name in keyJson){
               var lableSort = keyJson[name];
               //如果等于1，表示为id name,如果等于2，表示为class属性
               if(lableSort == 1){
                   var className =  $('#'+name);
                   console.log(className);
                   if(className){
                     $(className).hide();
                   }
                }else{
                     var idName = $('.'+name);
                     console.log(idName);
                     if(idName){
                      $(idName).hide();
                    }
                }
           }
           keyJson = localStorage.getItem('monkeyVoidAdWithP');
           keyJson = JSON.parse(keyJson);
           for(name in keyJson){
               var nodes = keyJson[name];
               console.log(nodes);
               nodes = JSON.parse(nodes);
               for(var item in nodes){
                   var node = nodes[item]
                   var la = node['lable'];
                   var lname = node['name'];
                   var num = node['num'];
                   if(la == 1){
                       var className =  $('.'+name).children(lname);
                       if(className && className[num-1]){
                         $(className[num-1]).hide();
                       }
                    }else{
                         var idName =  $('#'+name).children(lname);
                         if(idName && idName[num-1]){
                           $(idName[num-1]).hide();
                        }
                    }

               }
           }


       }else{
           clearInterval(clock); //清除js定时器
       }
   }
     //键盘事件

    $(document).keydown(function(e) {
　　if (e.ctrlKey && e.which == 37){
         var classIdName = prompt("这里针对屏蔽当前元素，id名称前写1,id:1id名字,class:2class名称");
         var labelsort = classIdName.substring(0,1);
         var labelName = classIdName.substring(1,classIdName.length);
         var keyJson = localStorage.getItem('monkeyVoidAd');
         console.log(keyJson);
         if(keyJson){
             console.log(keyJson);
             keyJson = JSON.parse(keyJson);
             console.log(keyJson);
             keyJson[labelName] = labelsort;
             localStorage.setItem('monkeyVoidAd',JSON.stringify(keyJson));
         }else{
             keyJson = {};
             keyJson[labelName] = labelsort;
             localStorage.setItem('monkeyVoidAd',JSON.stringify(keyJson));
         }
     }
     　if (e.ctrlKey && e.which == 39){
         var classIdName = prompt("这里针对屏蔽父级目录下的子元素，id名称前写1,id:1id名字,class:2class名称");
         var labelsort = classIdName.substring(0,1);
         var labelName = classIdName.substring(1,classIdName.length);
         var childeLable = prompt("请输入要屏蔽的子元素的属性，比如屏蔽父目录下的第2个div就写2-div,p标签就写2-p");
         var num = childeLable.split('-')[0];
         var childeName = childeLable.split('-')[1];
         var keyJson = localStorage.getItem('monkeyVoidAdWithP');
         var temp={};
         temp['lable']=1;
         temp['num']=num;
         temp['name'] = childeName;
         if(keyJson){
             keyJson = JSON.parse(keyJson);
             var value = keyJson[labelName];
             console.log(value)
             if(value){
                value = JSON.parse(value);
                var rcount=0;
                for(var item in value){
                    rcount++;
                }
                console.log(rcount)
                value[rcount+1] = temp;
             }else{
                var value={};
                value[0] = temp;
             }
             keyJson[labelName] = JSON.stringify(value);
             localStorage.setItem('monkeyVoidAdWithP',JSON.stringify(keyJson));
         }else{
             keyJson = {};
             var value={};
             value[0] = temp;
             keyJson[labelName] = JSON.stringify(value);
             localStorage.setItem('monkeyVoidAdWithP',JSON.stringify(keyJson));
         }
     }
     });

   //键盘事件结束
})();